<?php

/**
 * Classe contenente utility
 *
 * @author fabio
 */
class Util {

    /**
     * Converte un nome da camel notation (ElementName) in underscore notation (element_name)
     * @param <type> $field
     * @return <type>
     */
    public static function splitAndCombineAtUpperCase($field){

        $column = preg_replace('/([a-z0-9])?([A-Z])/','$1_$2',$field);

        return strtolower($column);

    }

    /**
     * Converte un nome da underscore notation (element_name) in camel notation (ElementName)
     * @param <type> $field
     * @return <type>
     */
    public static function splitAndCombineAtUnderscore($field){
        $entity = "";

        $columnArray = explode("_", $field);
        for($i = 0; $i < count($columnArray); $i++) {
            if($i > 0)
                $entity .= ucfirst($field[$i]);
            else
                $entity = $field[$i];
        }

        return $entity;

    }

    /**
     * Recupera l'elemento prima attraverso i parametri passati via POST e poi
     * parametri passati via GET
     * 
     * @param <type> $nomeElemento
     * @return <type>
     */
    public static function getElement($nomeElemento) {
        $value = null;

        if(isset($_POST[$nomeElemento]))
	      $value = $_POST[$nomeElemento];
        if(isset($_GET['username']))
	      $value = $_GET[$nomeElemento];

        return $value;
        
    }
}
?>
